package com.hgnu.dorm.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.util.SaResult;
import com.hgnu.dorm.domain.dto.StudentPageQueryDto;
import com.hgnu.dorm.domain.po.PageBean;
import com.hgnu.dorm.domain.po.Student;
import com.hgnu.dorm.service.StudentService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/students")
@SaCheckRole(value = {"admin","common"},mode = SaMode.OR)
@Tag(name = "学生管理接口")
public class StudentController {

    @Autowired
    private StudentService studentService;

    /**
     * 查询学生信息列表
     */
    @GetMapping
    public SaResult list(StudentPageQueryDto dto)
    {
        PageBean page = studentService.selectStudentList(dto);
        return SaResult.data(page);
    }


    /**
     * 获取学生信息详细信息
     */
    @GetMapping(value = "/{id}")
    public SaResult  getInfo(@PathVariable("id") Integer id)
    {
        return SaResult.data(studentService.selectStudentById(id));
    }

    /**
     * 新增学生信息
     */
    @PostMapping
    public SaResult  add(@RequestBody Student student)
    {
        return SaResult.data(studentService.insertStudent(student));
    }

    /**
     * 修改学生信息
     */
    @PutMapping
    public SaResult  edit(@RequestBody Student student)
    {
        return SaResult.data(studentService.updateStudent(student));
    }

    /**
     * 删除学生信息
     */
    @DeleteMapping("/{ids}")
    public SaResult  remove(@PathVariable Integer[] ids)
    {
        return SaResult.data(studentService.deleteStudentByIds(ids));
    }

}
